<template>
  <el-popover
    trigger="click"
    placement="bottom-start"
    style="max-height: 200px"
    content-style="padding: 0 8px;"
    :width="250"
  >
    <template #reference>
      <span><svg-icon icon-class="emoji"></svg-icon></span>
    </template>
    <div class="emoji-title">{{ emojiType === 0 ? '小黄脸' : emojiType === 1 ? 'tv_小电视' : '颜文字' }}</div>

    <div class="emoji-content" v-if="emojiType === 0">
      <span class="emoji-item" v-for="(value, key, index) of emojiList" :key="index" @click="addEmoji(key, emojiType)">
        <img :src="value" :title="key" class="emoji" width="24" height="24" />
      </span>
    </div>
    <div class="emoji-content" v-if="emojiType === 1">
      <span class="emoji-item" v-for="(value, key, index) of tvList" :key="index" @click="addEmoji(key, emojiType)">
        <img :src="value" :title="key" class="emoji" width="24" height="24" />
      </span>
    </div>
    <div class="emoji-content" v-if="emojiType === 2">
      <span class="text-emoji" v-for="(value, index) in textList" :key="index" @click="addEmoji(value, emojiType)">
        {{ value }}
      </span>
    </div>
    <div class="emoji-tabs">
      <div class="emoji-tab" :class="{ on: emojiType === 0 }" @click="chooseType(0)">
        <img src="http://hedongliang.com.cn/emoji/re.png" width="22" height="22" />
      </div>
      <!-- <div class="emoji-tab" :class="{ on: emojiType === 1 }" @click="chooseType(1)">
        <img src="" width="22" height="22" />
      </div> -->
      <div class="emoji-tab" :class="{ on: emojiType === 2 }" @click="chooseType(2)">
        <img src="http://hedongliang.com.cn/emoji/ywz.png" width="22" height="22" />
      </div>
    </div>
  </el-popover>
</template>

<script setup>
import SvgIcon from '@/components/svgIcon/index.vue';
import { emojiList } from '@/utils/emoji';
import { textList } from '@/utils/text';
import { tvList } from '@/utils/tv';
import { ref } from 'vue';
const emojiType = ref(0);
const emit = defineEmits(['addEmoji', 'chooseType']);
const addEmoji = (key, type) => {
  emit('addEmoji', { key, type });
};
const chooseType = (key) => {
  emojiType.value = key;
  emit('chooseType', key);
};
</script>

<style lang="scss" scoped>
.emoji-content {
  height: 120px;
  overflow: auto;
}

.emoji-item {
  cursor: pointer;
  display: inline-block;

  .emoji {
    user-select: none;
    margin: 5px;
    display: inline-block;
    vertical-align: middle;
  }
}

.text-emoji {
  display: inline-block;
  cursor: pointer;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 22px;
}

.emoji-item:hover,
.text-emoji:hover {
  transition: all 0.2s;
  border-radius: 5px;
  background: #ddd;
}

.emoji-tabs {
  display: flex;
  background-color: #fdfeff;

  .emoji-tab {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 58px;
    height: 36px;
    padding: 7px 18px;
    cursor: pointer;

    &:hover {
      background-color: #ddd;
    }
  }

  .on {
    background-color: #fff;
  }
}
</style>
